package nc.ui.medde.vocodegen;

import nc.md.gen.CodeGenException;
import nc.md.gen.CodeGenUtils;
import nc.md.gen.generator.ICodeGenerator;
import nc.md.gen.vmobj.AggVMObject;
import nc.md.gen.vmobj.IVMObject;
import nc.ui.medde.actions.menu.vocreate.CodeSwitch;
import nc.vo.database.support.Table;

/**
 * @author yany
 * 
 */
public class UapdeAggVoGenerator extends UapdeAbstractGenerator {

	private ICodeGenerator sVOgen;

	public UapdeAggVoGenerator(String destFolder, CodeSwitch codeSwitch, Table t) {
		super(destFolder, codeSwitch, t);
		setVmfile(AGGREGATED);
	}

	@Override
	protected IVMObject convertVMObject(Object object) throws CodeGenException {
		Table table = (Table) object;
		AggVMObject vmobj = new AggVMObject();
		String voName = getVoName(table);
		String[] pkgclz = CodeGenUtils.unCombineQualifiedClassname(voName);
		vmobj.setQualifiedName(pkgclz[0] + ".Agg" + pkgclz[1]);
		BaseVmObjectUtil.fillBaseInfo(vmobj, getCodeSwitch());
		vmobj.setParentvo(getVoName(table));
		return vmobj;
	}

	public void generateCode() throws CodeGenException {
		sVOgen = new UapdeSVoGenerator(destFolder, getCodeSwitch(),
				(Table) bean);
		sVOgen.generateCode();
		IVMObject vmobj = convertVMObject(bean);
		generate(vmobj);
	}

}